package connect4client.commands;

import messages.ListGamesReplyMessage;
import connect4client.core.GameManager;

/**
 * The ListPlayersReply command.
 * 
 * This command will handle ListPlayersReply messages.
 */
public class ListGamesReplyCommand extends Command {

	public ListGamesReplyCommand(ListGamesReplyMessage message){
		super(message);
	}
	
	@Override
	public void execute() {		
		GameManager gameManager = controller.getGameManager();
		ListGamesReplyMessage message = (ListGamesReplyMessage) this.message;
		
		synchronized (gameManager) {
			gameManager.getGames().clear();
			gameManager.getGames().addAll(message.getGames());
		}
		
		guiMediator.listGamesReply(message.getGames());
	}
}
